"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = {
  attachInfo: function attachInfo() {
    var res = wx.getSystemInfoSync();

    wx.WIN_WIDTH = res.screenWidth;
    wx.WIN_HEIGHT = res.screenHeight;
    wx.IS_IOS = /ios/i.test(res.system);
    wx.IS_ANDROID = /android/i.test(res.system);
    wx.STATUS_BAR_HEIGHT = res.statusBarHeight;
    wx.DEFAULT_HEADER_HEIGHT = 46; // res.screenHeight - res.windowHeight - res.statusBarHeight
    wx.DEFAULT_CONTENT_HEIGHT = res.screenHeight - res.statusBarHeight - wx.DEFAULT_HEADER_HEIGHT;
    wx.IS_APP = true;

    wx.showAlert = function (options) {
      options.showCancel = false;
      wx.showModal(options);
    };

    wx.showConfirm = function (options) {
      wx.showModal(options);
    };
  },
  getUserInfo: function getUserInfo(data, method) {
    var host = "https://api.bjlya.com.cn/xcx/app.php?";
    if (method == 'post') {
      wx.request({
        url: host,
        data: data,
        method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        success: function success(res) {
          wx.setStorageSync('info', res.data.info);
        }
      });
    } else if (method == 'get') {
      wx.request({
        url: host,
        data: data,
        method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        header: {
          'Content-Type': 'application/json'
        },
        success: function success(res) {
          wx.setStorageSync('info', res.data.info);
        }
      });
    }
  },
  login: function login(info) {
    var iv = info.detail.iv;
    var userInfo = info.detail.userInfo;
    var encryptedData = info.detail.encryptedData;
    if (userInfo) {
      wx.login({
        success: function success(response) {
          console.log(response);
          var code = response.code;
          var host = "https://api.bjlya.com.cn/xcx/app.php?";
          var data = {
            mod: "do",
            act: "openid",
            mid: code,
            iv: iv,
            encryptedData: encryptedData,
            cid: wx.getStorageSync('cid') || ''
          };
          wx.request({
            url: host,
            data: data,
            // method: 'post', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {
            //   'content-type': 'application/x-www-form-urlencoded'
            // },
            method: 'GET',
            header: {
              'content-type': 'application/json'
            },
            success: function success(result) {
              console.log(result);
              wx.setStorageSync('type', result.data.info.type);
              wx.setStorageSync('openid', result.data.info.ssid);
              var method = 'post';
              var host = "https://api.bjlya.com.cn/xcx/app.php?";
              var data = {
                mod: "do",
                act: "info",
                ssid: result.data.info.ssid
              };
              if (method == 'post') {
                wx.request({
                  url: host,
                  data: data,
                  method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
                  header: {
                    "Content-Type": "application/x-www-form-urlencoded"
                  },
                  success: function success(res) {
                    console.log(res);
                    wx.setStorageSync('info', res.data.info);
                  }
                });
              } else if (method == 'get') {
                wx.request({
                  url: host,
                  data: data,
                  method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
                  header: {
                    'Content-Type': 'application/json'
                  },
                  success: function success(res) {
                    console.log(res);
                    wx.setStorageSync('info', res.data.info);
                  }
                });
              }
            }
          });
        },
        fail: function fail(res) {
          wx.switchTab({
            url: '/pages/online/online'
          });
        }
      });
    } else {
      wx.switchTab({
        url: '/pages/online/online'
      });
    }
  }
};